<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title><fmt:message code="file.th.detail" /></title>
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="../js/news/page.js"></script>
    <script src="../lib/laydate/laydate.js"></script>
    <script src="../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/layer/layer.js?20201106"></script>
    <style>
        .head{
            font-size: 22px;
            color: #494d59;
            font-family: Microsoft yahei,Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;
        }
        .head span{
            margin-left: 24px;
            margin-top: 10px;
        }
        .content_table {
            margin: 20px auto;
            width: 88%;
        }
        a{
            text-decoration: none;
        }
        .closeWindow{
            width: 50px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            color: #ffffff;
            margin: 0 auto;
        }
    </style>
</head>
<body>

<div class="head">
    <span><fmt:message code="doc_th_seeFile" /></span>
</div>

<div class="content">
    <table class="content_table">

    </table>
</div>

<script type="text/javascript">
    var runId=0;
    $(function () {
        var dataId = $.GetRequest().fileId;
        $.ajax({
            url: "/rmsFile/selectById",
            data: {
                fileId: dataId
            },
            type: "get",
            success: function (res) {
                var str = '';
                if (res.flag) {
                    var object = res.object;

                    // 密级判断
                    if(object.secret==1){
                        object.secret = '<fmt:message code="dem.th.PuDense" />';
                    }else if(object.secret==2){
                        object.secret = '<fmt:message code="doc.th.Top-secret" />';
                    }else if(object.secret==3){
                        object.secret = '<fmt:message code="doc.th.Confidential" />';
                    }else if(object.secret==4){
                        object.secret = '<fmt:message code="doc.th.Secret" />';
                    }
                    //紧急等级判断
                    if(object.urgency == '1'){
                        object.urgency='<fmt:message code="hr.th.EmployeeType" />';
                    }else{
                        object.urgency='<fmt:message code="dem.th.GeneralLevel" />';
                    }
                    //文件分类判断
                    if(object.fileType == '1'){
                        object.fileType='<fmt:message code="email.th.document" />';
                    }else{
                        object.fileType='<fmt:message code="userDatails.th.data" />';
                    }
                    //公文类别判断
                    if(object.fileKind == '1'){
                        object.fileKind='A';
                    }else if(object.fileKind == '2'){
                        object.fileKind='B';
                    }else if(object.fileKind == '3'){
                        object.fileKind='C';
                    }else {
                        object.fileKind='D';
                    }
                    var arrAttach=object.attachmentList
                    var stra='';
                    if(arrAttach.length > 0){
                        for(var i=0;i<arrAttach.length;i++){
                            stra+= '<div class="dech" style="max-width: 550px;" deUrl="' + encodeURI(arrAttach[i].attUrl)+ '"><a title="'+ arrAttach[i].attachName +'" style="display:inline-block;width:100%;overflow: hidden; word-break:break-all;white-space: nowrap;text-overflow: ellipsis;" href="<%=basePath %>download?'+encodeURI(arrAttach[i].attUrl)+'" NAME="' + arrAttach[i].attachName + '*"><img style="margin-right:10px;" src="../img/attachment_icon.png"/>' + arrAttach[i].attachName + '</a></div>';
                        }
                    }else{
                        stra='<fmt:message code="hr.th.NoAttachments" />';
                    }

                    var arrAttach2 = object.attachmentList2;
                    var stra2 = '';
                    if (arrAttach2 && arrAttach2.length > 0){
                        for(var i=0;i<arrAttach2.length;i++){
                            stra2+= '<div class="dech" style="max-width: 550px;" deUrl="' + encodeURI(arrAttach2[i].attUrl)+ '"><a title="'+ arrAttach2[i].attachName +'" style="display:inline-block;width:100%;overflow: hidden; word-break:break-all;white-space: nowrap;text-overflow: ellipsis;" href="<%=basePath %>download?'+encodeURI(arrAttach2[i].attUrl)+'" NAME="' + arrAttach2[i].attachName + '*"><img style="margin-right:10px;" src="../img/attachment_icon.png"/>' + arrAttach2[i].attachName + '</a></div>';
                        }
                    } else {
                        stra2='无正文附件';
                    }

                    str += '<tr>' +
                        '   <td><fmt:message code="dem.th.FileNum" />：</td><td>'+object.fileCode+'</td>' +
                        '<td><fmt:message code="dem.th.DocumentWords" />：</td><td>'+object.fileSubject+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td><fmt:message code="dem.th.FileTitle" />：</td><td style="max-width: 300px;" title="'+object.fileTitle+'">'+object.fileTitle+'</td>' +
                        '<td><fmt:message code="dem.th.Supplemented" />：</td><td>'+object.fileTitle0+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td><fmt:message code="doc.th.DispatchUnit" />：</td><td>'+object.sendUnit+'</td>' +
                        '<td><fmt:message code="dem.th.DateWriting" />：</td><td>'+function () {
                            if(object.sendDate != undefined){
                                return object.sendDate;
                            }else{
                                return '';
                            }
                        }()+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td><fmt:message code="dem.th.Dense" />：</td><td>'+object.secret+'</td>' +
                        '<td><fmt:message code="dem.th.EmergencyGrade" />：</td><td>'+object.urgency+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td><fmt:message code="dem.th.FileClassification" />：</td><td>'+object.fileType+'</td>' +
                        '<td><fmt:message code="dem.thDocumentCategory" />：</td><td>'+object.fileKind+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td><fmt:message code="dem.th.FilePage" />：</td><td>'+object.filePage+'</td>' +
                        ' <td><fmt:message code="dem.th.Print" />：</td><td>'+object.printPage+'</td>' +
                        ' </tr>' +
                        ' <tr>' +
                        ' <td><fmt:message code="journal.th.Remarks" />：</td><td colspan="3">'+object.remark+'</td>' +
                        '</tr>' +
                        ' <tr>' +
                        ' <td style="min-width:80px;">文件正文：</td><td colspan="3">'+stra2+'</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td style="min-width:80px;"><fmt:message code="depatement.th.Attachmentdocument" />：</td><td colspan="3">'+stra+function(){
                            //lr添加按钮
                            if(object.runId!=null){
                             runId=object.runId
                            return "";
                                // '<button id="runIdButton" onclick="viewDetails()" style="width: 137px;\n' +
                                // '    height: 30px;\n' +
                                // '    line-height: 30px;\n' +
                                // '    text-align: center;\n' +
                                // '    background: #2b7fe0;\n' +
                                // '    border-radius: 4px;\n' +
                                // '    cursor: pointer;\n' +
                                // '    color: #ffffff;\n' +
                                // '    margin: 0 auto;">查看流程详情</button>'
                             }else{
                                return "";
                             }
                        }()+'</td>' +
                        '</tr>'+
                        '<tr>' +
                        '<td colspan="4"><div class="closeWindow">关闭</div></td>' +
                        '</tr>';
                }
                $('.content_table').html(str);
            },
            dataType: "json"
        });
        $('.content_table').on('click','.closeWindow',function () {
            window.close();

            var index = parent.layer.getFrameIndex(window.name);
            if (index) {
                parent.layer.close(index);
            }
        })
    })
    //lr添加查看权限
    function viewDetails () {

        $.ajax({
            type : "get",
            url : "/rmsFile/viewDetails",
            data: {
                "runId": runId
            },
            dataType:'json',
            success : function(result) {
                var data = result.object;
                if(result.flag){
                    window.open('/workflow/work/workformPreView?flowId='+data.flowId+'&runId='+data.runId);
                }else{
                    alert("对不起，您没有查看权限！")
                }
            }
        })
    }
</script>
</body>
</html>
